package com.team.service.Impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.team.dao.impl.EquipmentStockDaoImpl;
import com.team.entity.EquipmentStock;
import com.team.service.EquipmentStockService;

@Service
@Transactional
public class EquipmentStockServiceImpl implements EquipmentStockService {
	@Resource
	private EquipmentStockDaoImpl esl;

	public boolean addEquipmentStock(EquipmentStock equipmentStock) {
		EquipmentStock result = esl.selectEquipmentStockByName(equipmentStock.getName());
		Integer asset = esl.seleteAsset();
		if (asset > 0 && asset > equipmentStock.getPrice()) {
			if (result == null) {
				esl.saveEquipmentStock(equipmentStock);
				esl.updateAssetPrice(equipmentStock.getPrice());
				return true;
			} else {
				esl.updateEquipmentaddStock(equipmentStock);
				esl.updateAssetPrice(equipmentStock.getPrice());
				return true;
			}
		}else{
			return false;
		}
		

	}

	
	public Integer seleteAsset() {
		Integer asset = esl.seleteAsset();
		return asset;
	}


	@Override
	public EquipmentStock selectEquipmentStockByName(String name) {
		EquipmentStock equipmentStock = esl.selectEquipmentStockByName(name);
		return equipmentStock;
	}

}
